// src/services/api.js
import axios from 'axios';

const BASE_URL = 'http://localhost:8080/auth-server';

const api = axios.create({
    baseURL: BASE_URL,
    headers: {
        'Content-Type': 'application/json',
    }
});

export const getAuthUrl = (clientId) => {
    const redirectUri = `${window.location.origin}/callback`;
    return `${BASE_URL}/oauth2/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}`;
};

export const getToken = (code, clientId) => {
    const redirectUri = `${window.location.origin}/callback`;
    return api.post('/oauth2/token', null, {
        params: {
            code,
            client_id: clientId,
            redirect_uri: redirectUri
        }
    });
};

export const getClientConfigs = () => api.get('/api/config');

export const saveClientConfig = (config) => api.post('/api/config', config);

export const deleteClientConfig = (id) => api.delete(`/api/config/${id}`);